﻿@{
    Layout = null;
}

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>盘点差异</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>


    <script type="text/html" id="barDemo">
        <a title="明细" href="javascript:;" lay-event="dList" id="frmView"><i class="layui-icon">&#xe63c;</i></a>
    </script>
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body ">
                <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                  
                    <div class="layui-inline layui-show-xs-block">
                        <button class="layui-btn" id="barAdd" type="button" onclick="cData()"><i class="layui-icon"></i>差异处理</button>
                    </div>
                </form>
            </div>
            <div class="layui-card-body layui-table-body layui-table-main">
                <table class="layui-hide" id="list" lay-filter="list"></table>

            </div>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
    var pchCode = "0"
    var barType = "0";
    var types = "";
    $(function () {
        pchCode = getUrlVariable("pchCode");
        barType = getUrlVariable("barType");//Bar 条码 
        types = getUrlVariable("types");//0 1 亏 盈
        loadData();
    });


    function loadData() {
        var condition = "{\"pchCode\":\"" + pchCode + "\",\"barType\":\"" + barType + "\",\"typesCode\":\"" + types+"\"}";
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#list'
                , height: 'full-200'   //固定高度-即固定表头固定第一行首行
                //, url: "../ProCheck/GetDataList?condition=" + pchCode + "&dataType=diff&limit=" + barType + "&typesCode=" + types
                , url: "../ProCheck/GetDataList?condition=" + condition + "&dataType=diff"
                , skin: 'row' //表格风格
                , even: true
                , page: true //是否显示分页
                , limits: [50, 100, 150]
                , limit: 50 //每页默认显示的数量
                , cols: [[ //标题栏
                    { type: 'checkbox', fixed: 'left' }
                    , { field: 'barCode', align: 'center', title: '条码编码', width: 120 }
                    , { field: 'proCode', align: 'center', title: '存货编码', width: 110 }
                    , { field: 'proName', align: 'center', title: '存货名称', width: 130 }
                    , { field: 'spec', align: 'center', title: '规 格', width: 110 }
                    , { field: 'number', align: 'center', title: '数量', width: 110 }
                    , { field: 'done', align: 'center', title: '数据状态', width: 110 }
                    , { field: 'memo', align: 'center', title: '备注', width: 200 }
                    , { field: 'id', title: 'id', width: 80 }
                ]], done: function (res, curr, count) {
                    $("[data-field='id']").css('display', 'none');//隐藏列
                }
            });
        });
    }
    function cData() {
        layer.confirm('确认要处理选中差异数据？', function (index) {
            var etype = "";
            if (types == "1") {
                etype = "0";
            } else {
                etype = "1";
            }
            let table = layui.table
            let checkStatus = table.checkStatus('list'),
                data = checkStatus.data;
            var vCodes = "";
            for (var i = 0; i < data.length; i++) {
                if (data[i]["done"] != "未处理") {
                    layer.msg("已处理：" + data[i]["barCode"],{ icon: 2 });
                    vCodes = "";
                    return;
                } else {
                    vCodes += data[i]["id"] + ",";
                }
            }
            var positionCode = $("#position").val();
            if (vCodes != "") {
                vCodes = vCodes.substring(0, vCodes.length - 1);
                $.ajax({
                    url: '../ProCheck/DoCheckDiffer',
                    data: { ids: vCodes, barType: barType, enType: etype, positionCode: positionCode},
                    dataType: "json",
                    type: "POST",
                    async: false,
                    success: function (data) {

                        if (data.result) {
                            layer.msg("操作成功", {icon:1});
                            loadData();
                        } else {
                            layer.msg(data.message, { icon: 2 });
                        }
                    }
                });
            } else {
                layer.msg("请先选择数据！", { icon: 2});
            }


            layer.close(index);
        });

    }
</script>
